#!/usr/bin/python
#Auther : MillionLee

'''
Do dummypost by cron

do dummypost for everyone in the userlist same as "do dummypost"
but with date check
'''

import datetime
import pytz

from getDummyText import getDummyText
from doOAuthUpdate import OAuthUpdate
from userListMorau import getUserList
from userListCoushin import updateUser

poster = OAuthUpdate()
print 'Content-Type: text/plain'

for (key, (secret, name, lastUpdateDateStr)) in getUserList().items():
    dateStrNow = datetime.datetime.now(pytz.timezone("PRC")).strftime("%m%d%y")
    if dateStrNow == lastUpdateDateStr:
        #conti just when had been updated today.
        #either Before, after today or never(lastUpdateDateStr is blank), do post.
        continue
    try:
        #do post
        poster.setToken(key, secret)
        poster.update(getDummyText())
    except Exception, e:
        #print except, user name and his key
        print e, name, key
        continue
    else:
        #refresh the update time
        updateUser(key, lastUpdateDateStr = dateStrNow)
        
        